#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
LL rd(){
    LL x=0,f=1;
    char c = getchar();
    while(c<'0'||c>'9'){
        if(c=='-') f=-1;
        c = getchar();
    }
    while(c>='0'&&c<='9'){
        x = (x<<3)+(x<<1)+(c^48);
        c = getchar();
    }
    return x*f;
}
const int N = 1e5 + 5;
int n,m,L,V,p[N];
struct car{
    int d,v,a;
}E[N];
namespace sub1{
    vector<int>ck;
    bool cmp(car x,car y){
        return x.d<y.d;
    }
    void solve(){
        ck.clear();
        sort(E+1,E+1+n,cmp);
        for(int i=1;i<=n;i++){
            if(E[i].v<=V) continue;
            ck.pb(E[i].d);
        }
        int siz = ck.size(),cnt=0;
        for(int i=0;i<siz;i++){
            int v = ck[i];
            if(v>p[m]){
                break;
            }else cnt++;
        }
        if(!cnt) cout<<cnt<<' '<<m<<'\n';
        else cout<<cnt<<' '<<m-1<<'\n';
    }
}
bool check(int mid,car w){
        LL ps = mid;
        return 1ll*(ps-w.d)*2*w.a+1ll*w.v*w.v > 1ll*V*V;
    }
namespace sub2{
   vector<int>ck;
    bool cmp(car x,car y){
        return x.d<y.d;
    }
    int Find(car w){
        int l=0,r=m+1;
        while(l+1<r){
            int mid = l+r>>1;
            if(p[mid]<w.d) l=mid;
            else r=mid;
        }
        l=p[r]-1,r=L+1;
        while(l+1<r){
            int mid = l+r>>1;
            if(check(mid,w)) r=mid;
            else l=mid;
        }
        return r;
    }
    void solve(){
        ck.clear();
        sort(E+1,E+1+n,cmp);
        for(int i=1;i<=n;i++){
            LL v0=E[i].v;
            if(E[i].d>p[m]) continue;
            LL lim = Find(E[i]);
            if(lim>p[m]) continue;
            ck.pb(lim);
        }
        int siz = ck.size(),cnt=0;
        for(int i=0;i<siz;i++){
            int v = ck[i];
            if(v>p[m]){
                break;
            }else cnt++;
        }
        if(!cnt) cout<<cnt<<' '<<m<<'\n';
        else cout<<cnt<<' '<<m-1<<'\n';
    }
}
namespace sub3{
    vector<int>ck;
    int vis[25],res,cs[25],cnt;
    int calc(){
        int ct=0;
        memset(vis,0,sizeof vis);
        for(int i=0;i<ck.size();i++){
            int v = ck[i];
            //cout<<v<<' ';
            for(int j=1;j<=n;j++){
                if(vis[j]) continue;
                if(p[v]<E[j].d) continue;
                if(check(p[v],E[j])) {
                    vis[j] = 1;
                    ct++;
                }
            }
        }
        //cout<<'\n';
        return ct;
    }
    void dfs(int now){
        if(now==m+1){
            if(calc()==cnt) {
                int tmp =m-ck.size();
                res = max(res,tmp);
            }
            return;
        }
        ck.pb(now);
        dfs(now+1);
        ck.pop_back();
        dfs(now+1);
    }
    void solve(){
        cnt = res = 0;
        ck.clear();
        for(int i=1;i<=m;i++) ck.pb(i);
        cnt = calc();
        ck.clear();
        dfs(1);
        cout<<cnt<<' '<<res<<'\n';
    }
}
void solve(){
    n=rd(),m=rd(),L=rd(),V=rd();
    int f1=1,f2=1,f3=1;//0 > <
    for(int i=1;i<=n;i++){
        E[i].d=rd();
        E[i].v=rd();
        E[i].a=rd();
        if(E[i].a==0) f2=f3=0;
        if(E[i].a<0) f1=f2=0;
        if(E[i].a>0) f1=f3=0;
    }
    for(int i=1;i<=m;i++) p[i] = rd();
    if(f1) sub1::solve();
    else if(f2) sub2::solve();
    else if(n<=20) sub3::solve();
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T =rd();
    while(T--) solve();
    return 0;
}

